
USE [Sorteo]
GO

/****** Object:  StoredProcedure [proc_AccionLoadByPrimaryKey]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AccionLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AccionLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_AccionLoadByPrimaryKey]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[NumeroAccion],
		[PromocionId],
		[ParticipanteId],
		[Ganador]
	FROM [Accion]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_AccionLoadAll]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AccionLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AccionLoadAll];
GO

CREATE PROCEDURE [proc_AccionLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[NumeroAccion],
		[PromocionId],
		[ParticipanteId],
		[Ganador]
	FROM [Accion]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_AccionUpdate]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AccionUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AccionUpdate];
GO

CREATE PROCEDURE [proc_AccionUpdate]
(
	@Id int,
	@NumeroAccion int,
	@PromocionId int,
	@ParticipanteId int,
	@Ganador bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Accion]
	SET
		[NumeroAccion] = @NumeroAccion,
		[PromocionId] = @PromocionId,
		[ParticipanteId] = @ParticipanteId,
		[Ganador] = @Ganador
	WHERE
		[Id] = @Id


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [proc_AccionInsert]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AccionInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AccionInsert];
GO

CREATE PROCEDURE [proc_AccionInsert]
(
	@Id int = NULL output,
	@NumeroAccion int,
	@PromocionId int,
	@ParticipanteId int,
	@Ganador bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Accion]
	(
		[NumeroAccion],
		[PromocionId],
		[ParticipanteId],
		[Ganador]
	)
	VALUES
	(
		@NumeroAccion,
		@PromocionId,
		@ParticipanteId,
		@Ganador
	)

	SET @Err = @@Error

	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_AccionDelete]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AccionDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AccionDelete];
GO

CREATE PROCEDURE [proc_AccionDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Accion]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_CargaExcelLoadByPrimaryKey]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CargaExcelLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CargaExcelLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CargaExcelLoadByPrimaryKey]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[PromocionId],
		[Nombre],
		[Cedula],
		[Telefono],
		[Empresa],
		[MontoFactura],
		[FechaCarga]
	FROM [CargaExcel]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_CargaExcelLoadAll]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CargaExcelLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CargaExcelLoadAll];
GO

CREATE PROCEDURE [proc_CargaExcelLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[PromocionId],
		[Nombre],
		[Cedula],
		[Telefono],
		[Empresa],
		[MontoFactura],
		[FechaCarga]
	FROM [CargaExcel]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_CargaExcelUpdate]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CargaExcelUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CargaExcelUpdate];
GO

CREATE PROCEDURE [proc_CargaExcelUpdate]
(
	@Id int,
	@PromocionId int,
	@Nombre varchar(100),
	@Cedula varchar(30) = NULL,
	@Telefono varchar(30) = NULL,
	@Empresa varchar(50) = NULL,
	@MontoFactura money,
	@FechaCarga datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CargaExcel]
	SET
		[PromocionId] = @PromocionId,
		[Nombre] = @Nombre,
		[Cedula] = @Cedula,
		[Telefono] = @Telefono,
		[Empresa] = @Empresa,
		[MontoFactura] = @MontoFactura,
		[FechaCarga] = @FechaCarga
	WHERE
		[Id] = @Id


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [proc_CargaExcelInsert]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CargaExcelInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CargaExcelInsert];
GO

CREATE PROCEDURE [proc_CargaExcelInsert]
(
	@Id int = NULL output,
	@PromocionId int,
	@Nombre varchar(100),
	@Cedula varchar(30) = NULL,
	@Telefono varchar(30) = NULL,
	@Empresa varchar(50) = NULL,
	@MontoFactura money,
	@FechaCarga datetime
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CargaExcel]
	(
		[PromocionId],
		[Nombre],
		[Cedula],
		[Telefono],
		[Empresa],
		[MontoFactura],
		[FechaCarga]
	)
	VALUES
	(
		@PromocionId,
		@Nombre,
		@Cedula,
		@Telefono,
		@Empresa,
		@MontoFactura,
		@FechaCarga
	)

	SET @Err = @@Error

	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_CargaExcelDelete]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CargaExcelDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CargaExcelDelete];
GO

CREATE PROCEDURE [proc_CargaExcelDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CargaExcel]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_ParticipanteLoadByPrimaryKey]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ParticipanteLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ParticipanteLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ParticipanteLoadByPrimaryKey]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Nombre],
		[Cedula],
		[Telefono],
		[Empresa]
	FROM [Participante]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_ParticipanteLoadAll]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ParticipanteLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ParticipanteLoadAll];
GO

CREATE PROCEDURE [proc_ParticipanteLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Nombre],
		[Cedula],
		[Telefono],
		[Empresa]
	FROM [Participante]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_ParticipanteUpdate]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ParticipanteUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ParticipanteUpdate];
GO

CREATE PROCEDURE [proc_ParticipanteUpdate]
(
	@Id int,
	@Nombre varchar(200),
	@Cedula varchar(20) = NULL,
	@Telefono varchar(20) = NULL,
	@Empresa varchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Participante]
	SET
		[Nombre] = @Nombre,
		[Cedula] = @Cedula,
		[Telefono] = @Telefono,
		[Empresa] = @Empresa
	WHERE
		[Id] = @Id


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [proc_ParticipanteInsert]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ParticipanteInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ParticipanteInsert];
GO

CREATE PROCEDURE [proc_ParticipanteInsert]
(
	@Id int = NULL output,
	@Nombre varchar(200),
	@Cedula varchar(20) = NULL,
	@Telefono varchar(20) = NULL,
	@Empresa varchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Participante]
	(
		[Nombre],
		[Cedula],
		[Telefono],
		[Empresa]
	)
	VALUES
	(
		@Nombre,
		@Cedula,
		@Telefono,
		@Empresa
	)

	SET @Err = @@Error

	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_ParticipanteDelete]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ParticipanteDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ParticipanteDelete];
GO

CREATE PROCEDURE [proc_ParticipanteDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Participante]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_PromocionLoadByPrimaryKey]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PromocionLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PromocionLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PromocionLoadByPrimaryKey]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Nombre],
		[FechaInicio],
		[FechaFinal],
		[FechaCreacion],
		[Monto],
		[CantidadAcciones],
		[FavorecerMultiplesVeces]
	FROM [Promocion]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_PromocionLoadAll]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PromocionLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PromocionLoadAll];
GO

CREATE PROCEDURE [proc_PromocionLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[Nombre],
		[FechaInicio],
		[FechaFinal],
		[FechaCreacion],
		[Monto],
		[CantidadAcciones],
		[FavorecerMultiplesVeces]
	FROM [Promocion]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_PromocionUpdate]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PromocionUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PromocionUpdate];
GO

CREATE PROCEDURE [proc_PromocionUpdate]
(
	@Id int,
	@Nombre varchar(100),
	@FechaInicio datetime,
	@FechaFinal datetime,
	@FechaCreacion datetime,
	@Monto money = NULL,
	@CantidadAcciones int = NULL,
	@FavorecerMultiplesVeces bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Promocion]
	SET
		[Nombre] = @Nombre,
		[FechaInicio] = @FechaInicio,
		[FechaFinal] = @FechaFinal,
		[FechaCreacion] = @FechaCreacion,
		[Monto] = @Monto,
		[CantidadAcciones] = @CantidadAcciones,
		[FavorecerMultiplesVeces] = @FavorecerMultiplesVeces
	WHERE
		[Id] = @Id


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [proc_PromocionInsert]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PromocionInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PromocionInsert];
GO

CREATE PROCEDURE [proc_PromocionInsert]
(
	@Id int = NULL output,
	@Nombre varchar(100),
	@FechaInicio datetime,
	@FechaFinal datetime,
	@FechaCreacion datetime,
	@Monto money = NULL,
	@CantidadAcciones int = NULL,
	@FavorecerMultiplesVeces bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Promocion]
	(
		[Nombre],
		[FechaInicio],
		[FechaFinal],
		[FechaCreacion],
		[Monto],
		[CantidadAcciones],
		[FavorecerMultiplesVeces]
	)
	VALUES
	(
		@Nombre,
		@FechaInicio,
		@FechaFinal,
		@FechaCreacion,
		@Monto,
		@CantidadAcciones,
		@FavorecerMultiplesVeces
	)

	SET @Err = @@Error

	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_PromocionDelete]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PromocionDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PromocionDelete];
GO

CREATE PROCEDURE [proc_PromocionDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Promocion]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_SorteoLoadByPrimaryKey]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SorteoLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SorteoLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SorteoLoadByPrimaryKey]
(
	@Id int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[PromocionId],
		[Orden],
		[Ganadores],
		[Ejecutado]
	FROM [Sorteo]
	WHERE
		([Id] = @Id)

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_SorteoLoadAll]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SorteoLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SorteoLoadAll];
GO

CREATE PROCEDURE [proc_SorteoLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Id],
		[PromocionId],
		[Orden],
		[Ganadores],
		[Ejecutado]
	FROM [Sorteo]

	SET @Err = @@Error

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_SorteoUpdate]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SorteoUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SorteoUpdate];
GO

CREATE PROCEDURE [proc_SorteoUpdate]
(
	@Id int,
	@PromocionId int,
	@Orden int,
	@Ganadores int,
	@Ejecutado bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Sorteo]
	SET
		[PromocionId] = @PromocionId,
		[Orden] = @Orden,
		[Ganadores] = @Ganadores,
		[Ejecutado] = @Ejecutado
	WHERE
		[Id] = @Id


	SET @Err = @@Error


	RETURN @Err
END
GO




/****** Object:  StoredProcedure [proc_SorteoInsert]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SorteoInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SorteoInsert];
GO

CREATE PROCEDURE [proc_SorteoInsert]
(
	@Id int = NULL output,
	@PromocionId int,
	@Orden int,
	@Ganadores int,
	@Ejecutado bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Sorteo]
	(
		[PromocionId],
		[Orden],
		[Ganadores],
		[Ejecutado]
	)
	VALUES
	(
		@PromocionId,
		@Orden,
		@Ganadores,
		@Ejecutado
	)

	SET @Err = @@Error

	SELECT @Id = SCOPE_IDENTITY()

	RETURN @Err
END
GO


/****** Object:  StoredProcedure [proc_SorteoDelete]    Script Date: 2/6/2010 1:03:02 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SorteoDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SorteoDelete];
GO

CREATE PROCEDURE [proc_SorteoDelete]
(
	@Id int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Sorteo]
	WHERE
		[Id] = @Id
	SET @Err = @@Error

	RETURN @Err
END
GO

